﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using perfume.Models;
using perfume.Models.DB;
using perfume.Models.ViewModels;

namespace perfume.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
        private perfume_dbEntities per_db = new perfume_dbEntities();
        private Product_repository pr = new Product_repository();
        public int PageSize = 9;

        public ActionResult Contacts()
        {
            return View();
        }

        public ActionResult Help()
        {
            return View();
        }

        [Authorize]
        public ActionResult Welcome()
        {
            return View();
        }
       
        public ActionResult Search(string id)
        {
             
            List<product> product = pr.GetProductByName(id).ToList();
            return View(product);        
        }

        // GET: /Product/
        //  [OutputCache(Duration = 3600, VaryByParam = "none")]
        public ViewResult Index(int id=1)
        {
            int page = id;
            var product = per_db.products.Include("Category").OrderBy(p=>p.product_id).Skip((page-1) * PageSize).Take(PageSize);
            Session["page"] = (per_db.products.Count() / PageSize) + 1; ;
            
            //var product = per_db.products.Include("Category");
            return View(product.ToList());
        }

        
        //
        // GET: /Product/Details/5
        // [OutputCache(Duration = int.MaxValue, VaryByParam = "id")]
        public ViewResult Details(int id)
        {
            product product = per_db.products.Single(p => p.product_id == id);
            return View(product);
        }

        protected override void Dispose(bool disposing)
        {
            per_db.Dispose();
            base.Dispose(disposing);
        }

    }
}
